import { PullToRefresh } from "antd-mobile"
import React, { useEffect, useState } from "react"
import { httpJson } from "../../../../services/http"
import NormalCard from '../components/normal-card'

const DeliveringOrder: React.FC = () => {
    const [list, setList] = useState<any>([])
    const [loading, setLoading] = useState<boolean>(false)
    const getDeliveringOrderList = async () => {
        setLoading(true)
        httpJson('GET', '/api/order/getMerchantOrderList', { orderStatus: '1' })
            .then((res: any) => {
                setList(res.data.data)
                setLoading(false)
            })
            .catch(err => {
                console.log(err)
                setLoading(false)
            })
    }
    useEffect(() => {
        getDeliveringOrderList()
    }, [])
    return (
        <PullToRefresh
            onRefresh={getDeliveringOrderList}
        >
            {
                list && list.length > 0 &&
                list.map((item: any) => {
                    return <NormalCard currentKey="2" props={item} refresh={getDeliveringOrderList} />
                })
            }
            {
                !loading && !list.length && (
                    <p style={{ maxHeight: 800, minHeight: 600, textAlign: 'center', fontSize: 20, color: '#999', lineHeight: 20 }}>暂无数据...</p>
                )
            }
        </PullToRefresh>
    )
}

export default DeliveringOrder